package com.briup.estore.web.servlet;

import com.briup.estore.common.result.Result;
import com.briup.estore.common.dto.OrderSearchDTO;
import com.briup.estore.common.utils.JsonUtils;
import com.briup.estore.common.vo.OrderInfoVO;
import com.briup.estore.service.OrderService;
import com.briup.estore.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author briup-adam
 * @Date 2023/8/4 下午3:19
 * @Description 获取用户的订单列表
 **/
@WebServlet("/order/list")
public class OrderListServlet extends  BaseServlet {
    private OrderService orderService=new OrderServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userId = (String) req.getAttribute("userId");
        String data = readData(req);
        OrderSearchDTO dto = JsonUtils.toObject(data, OrderSearchDTO.class);
        List<OrderInfoVO> orders = orderService.getOrders(Integer.parseInt(userId), dto);
        writeData(resp, Result.success(orders));
    }
}
